/*
 * #%L
 * java model
 * %%
 * Copyright (C) 2009 - 2011 prefabware.com Stefan Isele
 * %%
 * All Rights Reserved.
 * This program is dual-licensed under the GNU General Public license
 * or a commercial license.
 * You may select to use one or the other of these licenses.
 * To obtain a commercial license please contact Stefan Isele at www.stefan-isele.de
 * Any modifications to this file must keep this entire header intact.
 * Redistribution, except as permitted by the selected license, is prohibited.
 * #L%
 */
package com.prefabware.jmodel.code;

import java.util.List;

import com.prefabware.commons.QualifiedName;
import com.prefabware.jmodel.JType;

public class JCodeOptionsBase implements JCodeOptions {

	private boolean useQualifiedNames;

	public JCodeOptionsBase(boolean useQualifiedNames) {
		super();
		this.useQualifiedNames = useQualifiedNames;
	}

	@Override
	public boolean isUseQualifiedNames() {
		return useQualifiedNames;
	}

	@Override
	public String asCode(QualifiedName qualifiedName) {
		if (this.isUseQualifiedNames()) {
			return qualifiedName.getName();
		} else {
			return qualifiedName.getSimpleName();
		}
	}
	/**
	 * @return a String containing the qualified names of all
	 *         {@link #types} seperated by ',' *
	 */
	public String toCsv(List<JType> types) {
		StringBuffer csv = new StringBuffer();
		String prepend = "";
		for (JType jType : types) {
			csv.append(prepend);
			if (this.isUseQualifiedNames()) {
				csv.append(jType.getQualifiedName().getName());
			}else{
				csv.append(jType.getQualifiedName().getSimpleName());
				
			}
			prepend = ",";
		}
		return csv.toString();
	}
}
